package cn.tonyandmoney.lib.webmagic.pipeline;

import cn.tonyandmoney.lib.webmagic.model.LawArticle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by niantuo on 2019/2/14.
 * 对结果进行保存吧
 */

public class LawSavePipeline implements Pipeline {

    private Logger logger = LoggerFactory.getLogger(LawSavePipeline.class);
    private List<LawArticle> articles = new ArrayList<>();

    @Override
    public void process(ResultItems resultItems, Task task) {
        LawArticle lawArticle = new LawArticle();
        lawArticle.setTitle(resultItems.get("title"));
        lawArticle.setContent(resultItems.get("content"));
        lawArticle.setCreateTime(resultItems.get("createTime"));
        lawArticle.setPublishTime(resultItems.get("publishTime"));
        lawArticle.setSummary(resultItems.get("summary"));
        articles.add(lawArticle);
    }

    public int getTotal() {
        return articles.size();
    }

    public List<LawArticle> getArticles(){
        return articles;
    }
}
